<?php
	#################################################################################################
	# functions
	#################################################################################################

	# 모든 라이브러리를 자동 임포트
	# 자식 클래스를 위해 '.'이 두개가 찍힌 부모 클래스를 선행 임포트한다.
	# 테스트 클래스는 접두 _ntdd_로써 임포트 하지 않는다.
	function class_autoload(){
		GLOBAL $DEFAULT_PATH;

		$path = opendir($DEFAULT_PATH.CLASSES_DIR);
		while ($list = readdir($path)) {
			if ($list != "." && $list != ".." && substr($list,0,6) != "_ntdd_" && $list != ".htaccess"){
				if(substr_count($list, ".") < 3){
					$arr_import_first[] = $list;
				} else{
					$arr_import_second[] = $list;
				}
			}
		}
		closedir($path);
		$arr_import = array_merge($arr_import_first, $arr_import_second);
		foreach($arr_import as $k=>$v){
			$inc = $DEFAULT_PATH.CLASSES_DIR.$v;
			include_once( $inc );
			$retarr[] = $inc;
		}
		return $retarr;
	}

	#// Turn off all error reporting
	#error_reporting(0);

	#// Report simple running errors
	#error_reporting(E_ERROR | E_WARNING | E_PARSE);

	#// Reporting E_NOTICE can be good too (to report uninitialized
	#// variables or catch variable name misspellings ...)
	#error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

	#// Report all errors except E_NOTICE
	#// This is the default value set in php.ini
	#error_reporting(E_ALL ^ E_NOTICE);

	#// Report all PHP errors (see changelog)
	#error_reporting(E_ALL);

	#// Report all PHP errors
	#error_reporting(-1);

	#// Same as error_reporting(E_ALL);
	#ini_set('error_reporting', E_ALL);

	#	value	constant
	#	1		E_ERROR
	#	2		E_WARNING
	#	4		E_PARSE
	#	8		E_NOTICE
	#	16		E_CORE_ERROR
	#	32		E_CORE_WARNING
	#	64		E_COMPILE_ERROR
	#	128		E_COMPILE_WARNING
	#	256		E_USER_ERROR
	#	512		E_USER_WARNING
	#	1024	E_USER_NOTICE
	#	2047	E_ALL
	#	2048	E_STRICT
	function error_reporting_handler() {
		if(APPMODE == 'dev') {
			# 개발 모드 이면
			ini_set('error_reporting', E_ALL);
			ini_set('display_errors', "on");
		} else {
			# 출시 모드 이면
			error_reporting(0);
			ini_set('display_errors', "off");
		}
		#ini_set('error_reporting',E_ALL & ~E_NOTICE | E_STRICT & ~E_DEPRECATED);
	}

	# error_listener
	#	errno
	#		The first parameter, errno, contains the level of the error raised, as an integer.
	#	errstr
	#		The second parameter, errstr, contains the error message, as a string.
	#	errfile
	#		The third parameter is optional, errfile, which contains the filename that the error was raised in, as a string.
	#	errline
	#		The fourth parameter is optional, errline, which contains the line number the error was raised at, as an integer.
	#	errcontext
	#		The fifth parameter is optional, errcontext, which is an array that points to the active symbol table at the point the error occurred. In other words, errcontext will contain an array of every variable that existed in the scope the error was triggered in. User error handler must not modify error context.
	function error_listener($errno, $errstr, $errfile, $errline, $errcontext) {
		if(APPMODE == 'dev') {
			$id = mt_rand(1, 999);
			echo sprintf("<div style=\"color:#00ff00;background-color:black; text-align:left; width:100%%;display:block;font:normal 16px/16px 'Fixedsys Excelsior 3.01', 'Bitstream Vera Sans Mono';\">error : [%s] %s in <strong>%s</strong> [%s] lines ",$errno, $errstr, $errfile, $errline);
			echo sprintf("	<span onclick=\"document.getElementById('%s').style.display = 'block';\" style=\"cursor:pointer;\">[more]</span>", $id);
			echo sprintf("	<xmp id=\"%s\" style=\"display:none;font:normal 16px/16px 'Fixedsys Excelsior 3.01', 'Bitstream Vera Sans Mono';\">%s</xmp>", $id, print_r($errcontext, true));
			echo sprintf("</div>");
		} else {
			return;
		}
	}

?>